<template>
  <div class="login">
    <div class="welcome">用户登录</div>
    <div class="login-form">
      <div class="login-inp"><label>账号</label>
        <input style="display: none;" />
        <input type="text" placeholder="账号" v-model.trim="username"></div>
      <div class="login-inp"><label>密码</label>
        <input type="password" placeholder="密码" v-model.trim="passwords"></div>
      <div class="login-inp"><a href="javascript:void(0)" @click="login">立即登录</a></div>
    </div>
    <div class="login-txt"><a href="javascript:void(0)" @click="$router.push('/register')">立即注册</a>|<a href="javascript:void(0)">忘记密码？</a></div>
  </div>


</template>

<script>
import { Toast } from 'mint-ui';
import { Indicator } from 'mint-ui';
import common from '../../common/common';
export default {
  name: 'Login',
  data () {
    return {
      username: '',
      passwords: ''
    };
  },
  methods: {
    login () {
      if(!this.username) return Toast({message: '请输入用户名！', position: 'bottom'});
      if(!this.passwords) return Toast({message: '请输入密码！', position: 'bottom'});

      const params = {
        username:this.username,
        password: this.passwords,
        device_type: common.isDeviceAllow()
      };

      Indicator.open('登录中...');
      common.request('login', params).then(res=>{
        var $data = res.data;
        if ($data.code > 0) {
          this.$cookies.set(
            common.conf.storageNamespace + 'token',
            $data.data.token,
            common.conf.TOKEN_EXPIRED_TIME
          );
          this.$router.push(this.$route.query.redirect || '/');
          Indicator.close();
        } else {
          Toast({message: $data.msg, position: 'bottom'});
          this.username = '';
          this.passwords = '';
          Indicator.close();

          // 无权登录-跳转联系我们页面
          // if($data.data.contact){
          //   this.$router.push({
          //     path:'/contact',
          //     query: {
          //       contact: JSON.stringify( Object.assign({msg:$data.msg}, $data.data.contact))
          //     }
          //   });
          // }
        }
      });
    }
  }
};
</script>

<style scoped>
@import url('./login-theme.css');
</style>
